package com.csthink.mysql.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csthink.mysql.entity.Account;
import com.csthink.mysql.mapper.AccountMapper;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * @author <a href="mailto:security.2009@live.cn">Mars</a>
 * @since 2023-09-10
 */
@Repository
public class AccountRepository extends ServiceImpl<AccountMapper, Account> {

    @Setter(onMethod_ = @Autowired)
    private AccountMapper accountMapper;

    public Account getAccountWithName(String name) {
        LambdaQueryWrapper<Account> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(Account::getName, name);
        return accountMapper.selectOne(queryWrapper);
    }

    public Account getAccountWithEmail(String email) {
        return accountMapper.getAccountWithEmail(email);
    }
}
